<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>添加合同</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script src="${ctx}/rs/js/jquery.validate.min.js"></script>
<script src="${ctx}/rs/js/jquery.form.js" type="text/javascript"></script>
<style>
.time label{
    margin-top:0 !important;
}
#payWay-error {
    margin-top:0 !important;
}

</style>
</head>
<body>
<form id="form1" class="form-horizontal" action="${ctx}/contract/sellsave.htm" method="post">
      <div class="form-group">
        <label for="name" class="col-sm-3 control-label item ">合同编号：</label>
        <div class="col-sm-8  ">
          <input type="text" class="form-control"placeholder="请输入合同编号" id="contractCode" name="contractCode" />
        </div>
        <span class="help-block col-sm-1" id="valierr" style="color:#FF9966">*</span>
      </div>

      <div class="form-group">
        <label for="name" class="col-sm-3 control-label item ">广告客户：</label>
        <div class="col-sm-8  ">
          <input type="text" class="form-control " id="advName"placeholder="请输入广告客户名称" name="advName"/>
        </div>
        <span class="help-block col-sm-1" id="valierr" style="color:#FF9966">*</span>
      </div>
      
      <div class="form-group">
        <label for="name" class="col-sm-3 control-label item ">签约总金额：</label>
        <div class="col-sm-8  ">
          <input type="text" class="form-control " id="signSumMoney"placeholder="请输入签约总金额" name="signSumMoney"/>
        </div>
        <span class="help-block col-sm-1" id="valierr" style="color:#FF9966">*</span>
      </div>
      <div class="form-group">
        <label for="name" class="col-sm-3 control-label item ">应付总金额：</label>
        <div class="col-sm-8  ">
          <input type="text" class="form-control " id="copewithMoney"placeholder="请输入应付总金额"  name="copewithMoney"/>
        </div>
        <span class="help-block col-sm-1" id="valierr" style="color:#FF9966">*</span>
      </div>
      <div class="form-group">
        <label for="name" class="col-sm-3 control-label item ">媒体投放总金额：</label>
        <div class="col-sm-8  ">
          <input type="text" class="form-control " id="throwMoney"placeholder="请输入媒体投放金额"  name="throwMoney"/>
        </div>
        <span class="help-block col-sm-1" id="valierr" style="color:#FF9966">*</span>
      </div>
      <div class="form-group">
        <label for="name" class="col-sm-3 control-label item ">结算方式：</label>
        <div class="col-sm-8  ">
           <select class="srt-put1 mr10 widput1" id="payWay" name="payWay">
             <option value="" selected="selected">请选择结算方式</option>
             <option value="0" >预付</option>
             <option value="1" >月结</option>
           </select>
        </div>
        <span class="help-block col-sm-1" id="valierr" style="color:#FF9966">*</span>
      </div>
      <div class="form-group">
        <label for="name" class="col-sm-3 control-label item ">签约日期：</label>
        <div class="col-sm-8  ">
          <span class="time"><input type="text" id="signTime" name= "signTime" class="srt-put1 mr10 widput1" 
              onfocus="WdatePicker()" />
        </div>
        <span class="help-block col-sm-1" id="valierr" style="color:#FF9966">*</span>
      </div>
      <div class="form-group">
        <label for="name" class="col-sm-3 control-label item ">合同有效期：</label>
        <div class="col-sm-8  ">
          <span class="time">
          <input type="text" id="timeToTime" name = "timeToTime" class="srt-put1 mr10 widput1" 
                 onfocus="WdatePicker()" />至 &nbsp; <input
                 type="text" id="timeToTime1" name="timeToTime1" class="srt-put1 mr10 widput1" 
                 onfocus="WdatePicker({minDate:'#F{$dp.$D(\'timeToTime\')}'})" /></span>
        </div>
        <span class="help-block col-sm-1" id="valierr" style="color:#FF9966">*</span>
      </div>
      <div class="form-group">
        <label for="name" class="col-sm-3 control-label item ">合同状态：</label>
        <div class="col-sm-8  ">
           <select class="srt-put1 mr10 widput1" id="contractStatus" name="contractStatus">
             <option value="" selected="selected">请选择合同状态</option>
             <option value="0" >未启动</option>
             <option value="1" >执行中</option>
             <option value="2" >结束</option>
           </select>
        </div>
        <span class="help-block col-sm-1" id="valierr" style="color:#FF9966">*</span>
      </div>
      <div class="form-group">
        <label for="name" class="col-sm-3 control-label item ">销售员：</label>
        <div class="col-sm-8  ">
          <input type="text" class="form-control" placeholder="请输入销售员名称" id="salesperson" name="salesperson"/>
        </div>
        <span class="help-block col-sm-1" id="valierr" style="color:#FF9966">*</span>
      </div>
      <div class="form-group">
        <label for="name" class="col-sm-3 control-label item ">合同情况：</label>
        <div class="col-sm-8  ">
          <textarea type="text" class="form-control " id="remarks" placeholder="请备注相关合同情况" name="remarks"/>
        </div>
        <span class="help-block col-sm-1" id="valierr" style="color:#FF9966">*</span>
      </div>
      <div class="form-group">
        <div class="col-sm-10 text-center pt15">
          <shiro:hasPermission name="message:save">
             <button type="button" class="btn btn-primary btn-lg srt-btn active mr30" onclick="valiSubmit()">确定</button>
             <button type="reset" class="btn btn-default btn-lg srt-btn active">重置</button>
          </shiro:hasPermission>
        </div>
      </div>

      <div class="form-group">
        <div class=" col-sm-10">
          <span id="error-text" style="color: #FF0000;"></span>
        </div>
      </div>
</form>


<script type="text/javascript" src="${ctx}/rs/js/bootstrapQ.min.js"></script>
<script src="${ctx}/rs/js/messages_zh.min.js"></script>
<script type="text/javascript">
$.validator.addMethod("limitType", function(value, element) {
    var str = value.substr(value.lastIndexOf(".")).toLowerCase();
    return this.optional(element) || /.(png|jpg)$/.test(str);
}, "上传文件格式不正确!");
$.validator.addMethod("moneyType", function(value, element) {
    return this.optional(element) || /^(\-?(0|[1-9]\d{0,})((\.[0-9]{1,2})?))$/.test(value);
}, "输入金额不正确!");
    //初始化验证 start
    var form = $('#form1');
    form.validate({
        rules: {
        	contractCode: {
                maxlength: 35,
                required: true,
                remote : {
                    type : "GET",
                    url : "${ctx}/contract/checkCode.htm",
                    data : {
                    	contractCode : function() {
                            return encodeURIComponent($("#contractCode").val());
                        }
                    }
                }
            },
            advName: {
                maxlength: 35,
                required: true
            },
            signSumMoney: {
            	moneyType:"moneyType",
                required: true
            },
            copewithMoney: {
            	moneyType:"moneyType",
                required: true
            },
            throwMoney: {
            	moneyType:"moneyType",
                required: true
            },
            payWay: {
                required: true
            },
            signTime: {
                required: true
            },
            timeToTime: {
                required: true
            },
            timeToTime1: {
                required: true
            },
            payWay: {
                required: true
            },
            contractStatus: {
                required: true
            },
            salesperson: {
            	maxlength: 35,
                required: true
            },
            remarks: {
                maxlength: 500,
                required: true
            }
          },
          messages: {
        	  contractCode: {
                remote: '销售编号不可重复'  
              }
          },
          highlight: function(element) {
              $(element).closest('.form-group').removeClass('success').addClass('error');
          },
          success: function(element) {
              element.text('OK!').addClass('valid')
              .closest('.form-group').removeClass('error').addClass('success');
          }
    });
    /** end */

   function valiSubmit() {
    if (form.valid() ) {
        var options = {
                dataType : "json",
                data : {
                    data : $("#form1").serialize()
                },
                beforeSubmit : function() {
                    $(".unable").show();
                },
                success : function(result) {
                  
                    if (result) {
                        // 普通消息提示条
                        bootstrapQ.msg({
                            msg : '发布成功！',
                            type : 'success',
                            time : 2000
                        });
                        //触发隐藏确认的按钮，引用回调方法关闭窗口并刷新列表
                        $("button.bsok").click();
                    } else {
                        bootstrapQ.msg({
                            msg : '发布失败！',
                            type : 'danger',
                            time : 2000
                        });
                    }
                },
                error : function(result) {
                    if (!$('.unable').is(':hidden')) {
                        $(".unable").hide();
                    }
                    bootstrapQ.msg({
                        msg : '发布失败！',
                        type : 'danger',
                        time : 2000
                    });
                }
            };
            form.ajaxSubmit(options);
        }
    }
</script>
</body>
</html>